package logic

import (
	"context"
	"gorm.io/gorm"
	"store/models/mysql"

	"store/storerpc/internal/svc"
	"store/storerpc/storerpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type StorerpcUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewStorerpcUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StorerpcUpdateLogic {
	return &StorerpcUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *StorerpcUpdateLogic) StorerpcUpdate(in *storerpc.StorerpcUpdateRequest) (*storerpc.StorerpcUpdateResponse, error) {
	// todo: add your logic here and delete this line
	var a = mysql.Merchants{
		Model: gorm.Model{ID: uint(in.Id)},
		Name:  in.Name,
		Types: in.Types,
	}
	mysql.DB.Debug().Where("id = ?", a.ID).Updates(&a)
	return &storerpc.StorerpcUpdateResponse{
		Id: in.Id,
	}, nil
}
